package com.huawei.hms.framework.network.restclient;

import java.util.Arrays;

public class Response<T> {
    private T body;
    private int code;
    private byte[] errorBody;
    private Headers headers;
    private String message;

    public static class Builder<T> {
        private T body;
        private int code;
        private byte[] errorBody;
        private Headers headers = new com.huawei.hms.framework.network.restclient.Headers.Builder().build();
        private String message;

        public Builder message(String str) {
            this.message = str;
            return this;
        }

        public Builder code(int i) {
            this.code = i;
            return this;
        }

        public Builder headers(Headers headers) {
            this.headers = headers;
            return this;
        }

        public Builder body(T t) {
            this.body = t;
            return this;
        }

        public Builder errorBody(byte[] bArr) {
            this.errorBody = bArr;
            return this;
        }

        public Response build() {
            return new Response(this);
        }
    }

    public Response(Builder<T> builder) {
        this.headers = builder.headers;
        this.code = builder.code;
        this.message = builder.message;
        this.body = builder.body;
        this.errorBody = builder.errorBody;
    }

    public int getCode() {
        return this.code;
    }

    public String getMessage() {
        return this.message;
    }

    public boolean isOK() {
        return this.code == 200;
    }

    public boolean isSuccessful() {
        return this.code >= 200 && this.code < 300;
    }

    public T getBody() {
        return this.body;
    }

    public byte[] getErrorBody() {
        if (this.errorBody == null) {
            return new byte[0];
        }
        return Arrays.copyOf(this.errorBody, this.errorBody.length);
    }

    public Headers getHeaders() {
        return this.headers;
    }

    public String toString() {
        return super.toString();
    }
}
